package com.tom.architect.party5.day37.simple2;

import com.tom.architect.party4.day35.simple2.BaseSubscriber;

/**
 * P层: 关联解耦M,V
 */
public class UserInfoPresenter implements UserInfoContract.UserInfoPresenter {
    // 持有 View 和 Model
    private UserInfoContract.UserInfoView mView;
    private UserInfoContract.UserInfoModel mModel;
    // V从外面传入
    public UserInfoPresenter(UserInfoContract.UserInfoView view) {
        this.mView = view;
        this.mModel = new UserInfoModel();
    }

    @Override
    public void getUsers(String token) {
        // RxJava + OkHttp + Retrofit 或 网络引擎 或okhttp
        // 拿到数据
        // 显示正在加载中。
        mView.onLoading();
        mModel.getUsers(token).subscribe(new BaseSubscriber<UserInfo>() {
            @Override
            protected void onError(String errorCode, String errorMessage) {
                mView.onError();
            }

            @Override
            public void onNext(UserInfo userInfo) {
                mView.onSucceed(userInfo);
            }
        });
    }


}
